var neutralGear = {
	TiemList: [],
	MonthInd: [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31],
	TYear: new Date().Format("yyyy"),
	TMonth: new Date().Format("MM"),
	getYear: function(date) {
		return parseInt(new Date(date).Format("yyyy"))
	},
	getMonth: function (date) {
		return parseInt(new Date(date).Format("MM"))
	},
	getDay: function (date) {
		return parseInt(new Date(date).Format("dd"))
	},
	isLeapYear: function (Year) {
	    var cond1 = Year % 4 == 0; 
	    var cond2 = Year % 100 != 0;  
	    var cond3 = Year % 400 ==0;  
	    var cond = cond1 && cond2 || cond3;
	    if(cond) {
	        this.MonthInd[1] = 29;
	    } else {
	        this.MonthInd[1] = 28;
	    }
	    this.initTiemList(this.MonthInd);
	},
	DayForFun: function(Month ,MonthInd){
		var monthArray = [];
		for (var i = 0; i < MonthInd[Month]; i++) {
			monthArray.push(false);
		}
		return monthArray;
	},
	initTiemList: function(MonthInd){
		for (var i = 0; i < MonthInd.length; i++) {
			this.TiemList.push({
					month: i+1,
					pastDue: i+1 >= parseInt(this.TMonth) ? true : false,
					day: this.DayForFun(i, MonthInd),
					data: []
			})
		}
	},
	integerMonth: function(time, MonthInd) {
		for (var i = 0; i < MonthInd[time]; i++) {
			this.TiemList[time].day[i] = true ;
		}
	},
	StartDateFun: function(start, MonthInd) {
		var Month = this.getMonth(start);
		var Day  = this.getDay(start);
		for (var i = Day; i <= MonthInd[Month-1]; i++) {
			this.TiemList[Month-1].day[i-1] = true ;
		}
	},
	endDateFun: function(end) {
		var Month = this.getMonth(end);
		var Day  = this.getDay(end);
		for (var i = 1; i <= Day; i++) {
			this.TiemList[Month-1].day[i-1] = true ;
		}
	},
	MonthCenterDate: function(start, end) {
		var Month = this.getMonth(start);
		var SDay  = this.getDay(start);
		var EDay  = this.getDay(end);

		for (var i = SDay; i <= EDay; i++) {
			this.TiemList[Month-1].day[i-1] = true ;
		}
	},

	getMonthSandE: function(start, end) {
		var SMonth = this.getMonth(start);
		var EMonth = this.getMonth(end);

		if (SMonth != EMonth) {
			for (var i = (SMonth+1); i < EMonth; i++) {
				this.integerMonth(i-1, this.MonthInd);
			}
			this.StartDateFun(start, this.MonthInd);
			this.endDateFun(end);
		}else{
			this.MonthCenterDate(start, end)
		}
	},
	getStartTo: function (start) {
		var Month = this.getMonth(start);
		for (var i = (Month +1); i <= 12; i++) {
			this.integerMonth(i-1, this.MonthInd)
		}
		this.StartDateFun(start, this.MonthInd)
	},
	getEndToOne: function(end) {
		var Month = this.getMonth(end);
		for (var i = (Month -1); i >= 1; i--) {
			this.integerMonth(i-1, this.MonthInd)
		}
		this.endDateFun(end);
	},
	isEquallyYear: function(start, end, TYear) {
		var Start = this.getYear(start);
		var End = this.getYear(end);
		if (TYear == Start || TYear == End) {
			if (TYear == Start && TYear == End) {
				this.getMonthSandE(start, end)
			}else if (TYear == Start && TYear != End) {
				this.getStartTo(start)
			}else if (TYear != Start && TYear == End) {
				this.getEndToOne(end)
			}
		}else{
			// console.log('不是今年数据');
		}
	},
	unifyPercent: function(TiemList, MonthInd) {
		for (var i = 0; i < TiemList.length; i++) {
			var index = 0;
			var isbl = TiemList[i].day[0];
			var ind = 0;
			for (var j = 0; j < TiemList[i].day.length; j++) {
				if (TiemList[i].day[j] == isbl) {
					index ++ ;
				}else{
					TiemList[i].data.push({
						isTrue: isbl,
						price: parseInt(index / MonthInd[i]*100)
					})
					ind += parseInt(index / MonthInd[i]*100)
					isbl = TiemList[i].day[j];
					index = 0;
				}

			}
			TiemList[i].data.push({
				isTrue: isbl,
				price: 100 - ind
			})

		}
	},
	StartFun: function (datelist) {
		this.isLeapYear(this.TYear);
		for (var i = 0; i < datelist.length; i++) {
			var start = datelist[i].starttime;
			var end =   datelist[i].endtime;
			this.isEquallyYear(start, end, this.TYear)
		}
		this.unifyPercent(this.TiemList, this.MonthInd);
		return this.TiemList;
	},
	StartFunTwo: function() {
		return this.TYear;
	}
}

export default neutralGear;